package com.fenda.servlet;

import com.fenda.Dao.UserDao;
import com.fenda.Util.mybatisUtil;
import com.fenda.pojo.Student;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/select")
public class SelectServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        SqlSession sqlSession = mybatisUtil.getSqlSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        List<Student> students =mapper.SelectAll();
        req.setAttribute("list",students);
        req.getRequestDispatcher("login.jsp").forward(req,resp);
//        resp.sendRedirect("login.jsp");
        for (Student student : students) {
            System.out.println(student);
        }

    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
        this.doGet(req,resp);
    }
}
